<?php

class Webmix_Bootstrap extends Engine_Application_Bootstrap_Abstract
{
    public function __construct($application)
    {
        parent::__construct($application);
        $this->addScriptJs();
        
        $viewer = Engine_Api::_()->user()->getViewer();
        if(!empty($viewer->user_id)){
            $webmixTable = Engine_Api::_()->getDbtable('webmixes','webmix');
            $select = $webmixTable->select()
                          ->where('content_type = 1')
                          ->where('owner_id = ?',$viewer->user_id);
            $row = $webmixTable->fetchRow($select);
            if  (!$row){
                $row = $webmixTable->createRow();
                $row->title = "Music";
                $row->type = Webmix_Model_Webmix::WEBMIX_TYPE_USER;
                $row->content_type = 1;
                $row->owner_id = $viewer->user_id;
                $row->country_id = 0;
                $row->save();
            }
        }
        
    }
    
    public function addScriptJs(){
        $view = Zend_Registry::get('Zend_View');
        $view->headScript()->appendFile($view->baseUrl() . '/application/modules/Webmix/externals/scripts/main.js') ;
    }
}